<template>
  <div class="llmxcx">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="90px" style="margin-top: 20px">
       <el-form-item label="申请月份" >
        <el-date-picker
          @change="search"
        class="datawidth"
          v-model="queryParams.planMonth"
          type="month"
          format="yyyy-MM"
          value-format="yyyy-MM"
          size="small"
          placeholder="选择月">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="申请日期">
        <el-date-picker v-model="date" size="small" value-format="yyyy-MM-dd" class="datawidth"
            type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"
            @change="dateSelect"></el-date-picker>
      </el-form-item>
        <el-form-item label="战线区队" >
          <el-select  size="small" v-model="queryParams.deptName" placeholder="请选择区队战线" ref="selectReportqd" clearable @clear="setValueNullqd">
            <el-option  :value="queryParams.depId" :label="queryParams.deptName" style="width:199px;height:200px;overflow: auto;background-color:#fff">
              <el-tree
                highlight-current
                :data="reportDataqd"
                :props="defaultPropsqd"
                 accordion
                @node-click="handleNodeClickSJqd"
              ></el-tree>
            </el-option>
          </el-select>
        </el-form-item>
      <el-form-item label="班组名称" >
        <el-select
          @change="search"
          v-model="queryParams.teamId"
          placeholder="请选择"
          clearable
          size="small"
        >
          <el-option
            v-for="(item,index) in banzhuArr"
            :key="index"
            :label="item.deptName"
            :value="item.deptId"
          />
        </el-select>
      </el-form-item>
        <el-form-item label="审核状态" >
          <el-select
            @change="search"
            v-model="queryParams.auditSteps"
            placeholder="请选择"
            clearable
            size="small"
          >
            <el-option
              v-for="(item,index) in shZT"
              :key="index"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="仓库名称" >
          <el-select size="small" v-model="queryParams.wnameSJ" placeholder="请选择上级仓库" ref="selectReport" clearable @clear="setValueNull">
            <el-option :value="queryParams.id" :label="queryParams.wname" style="width:199px;height:200px;overflow: auto;background-color:#fff">
              <el-tree
                node-key="id"
                :default-expanded-keys="[1]"
                highlight-current
                :data="reportData"
                :props="defaultProps"
                @node-click="handleNodeClickSJ"
              ></el-tree>
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="物料名称" >
          <el-input
            v-model="queryParams.mName"
            placeholder="请输入物料名称"
            clearable
            @change="search"
            size="small"
          />
        </el-form-item>
        <el-form-item label="物料编码" >
          <el-input
            @change="search"
            v-model="queryParams.mNo"
            placeholder="请输入物料编码"
            clearable
            size="small"
          />
        </el-form-item>
      <el-form-item label="费用来源">
        <el-select v-model="queryParams.cpName" placeholder="请选择" size="small"  @change="search">
          <el-option
            v-for="item in cpNameArr"
            :key="item.cpName"
            :label="item.cpName"
            :value="item.cpName">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button   type="primary" icon="el-icon-search" size="mini" @click="search">搜索</el-button>
        <el-button   type="warning" icon="el-icon-download" size="mini" @click="exportList">导出</el-button>

      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="roleList" stripe border>
      <el-table-column align="center" type="index" label="序号"  width="55"  />
      <el-table-column align="center" label="审核状态"   property="auditSteps"  width="100" >
        <template slot-scope="scope" style="text-align: center">
          <div style="background:#9E71DC  ;color: white;width: 54px;height: 22px;display: inline-block" v-show="scope.row.auditSteps==1">未提交</div>
          <div style="background:#78BF34  ;color: white;width: 54px;height: 22px;display: inline-block" v-show="scope.row.auditSteps==2">待审核</div>
          <div style="background:#9E71DC  ;color: white;width: 54px;height: 22px;display: inline-block" v-show="scope.row.auditSteps==3">驳回</div>
          <div style="background:#DEA11E  ;color: white;width: 54px;height: 22px;display: inline-block" v-show="scope.row.auditSteps==4">通过</div>
        </template>
      </el-table-column>
      <el-table-column align="center" label="申请出库"  property="pickName" ></el-table-column>
      <el-table-column align="center" label="所在库"  property="waName" ></el-table-column>
      <el-table-column align="center" label="部门"  property="deptName" ></el-table-column>
      <el-table-column align="center" label="区队"  property="teamName" ></el-table-column>
      <el-table-column align="center" label="申请人"  property="crtUserName" ></el-table-column>
      <el-table-column align="center" label="物料编码"  property="mno" ></el-table-column>
      <el-table-column align="center" label="物料名称"  property="mname" ></el-table-column>
      <el-table-column align="center" label="物料规格"  property="mmodel" ></el-table-column>
      <el-table-column align="center" label="单位"  property="unit" ></el-table-column>
      <el-table-column align="center" label="计划价"  property="planPrice" ></el-table-column>
      <el-table-column align="center" label="申请数"  property="demandNum" ></el-table-column>
      <el-table-column align="center" label="金额"  property="amount" ></el-table-column>
      <el-table-column align="center" label="备注"  property="note" ></el-table-column>
      <el-table-column align="center" label="申请时间"  property="crtTime" :show-overflow-tooltip="true" ></el-table-column>
    </el-table>
    <div class="bottomflot">
      <pagination
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="search"
      >
      </pagination>
      <span class="box">当页总金额: <b>{{curPageAmount}}</b>   总金额: <b>{{curMonthAmount}}</b> </span>
    </div>
  </div>
</template>

<script>
  import request from '@/utils/request'

  export default {
    name: "Role",
    components:{

    },
    data() {
      return {
        //班组名称
        banzhuArr:[],
        cpNameArr:[],
        //日期范围
        date:[],
        //审核状态
        shZT:[
          {value:'1',label:'未提交'},
          {value:'2',label:'待审核'},
          {value:'3',label:'驳回'},
          {value:'4',label:'通过'},
        ],
        reportData:[],
        // 遮罩层
        loading: false,
        // 总条数
        total: 0,
        // 角色表格数据
        roleList: [],
        // 日期范围
        dateRange: [],

        // 数据范围选项
        dataScopeOptions: [
          {
            value: "1",
            label: "全部数据权限"
          },
          {
            value: "2",
            label: "自定数据权限"
          },
          {
            value: "3",
            label: "本部门数据权限"
          },
          {
            value: "4",
            label: "本部门及以下数据权限"
          },
          {
            value: "5",
            label: "仅本人数据权限"
          }
        ],
        // 菜单列表
        menuOptions: [],
        // 部门列表
        deptOptions: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          planMonth:'',
          startDate:'',
          endDate:'',
          isStorage: 1,
          auditSteps:'',
          mName:'',
          cpName:'',
          mNo:'',
          depId:'0',
          teamId:'',
          waId:'',
          id:'',
          wnameSJ:'全部',
          deptName:'全部',
        },
        // 表单参数
        form: {},
        defaultProps: {
          children: "childList",
          label: "wname"
        },
        defaultPropsqd:{
          children:'children',
          label:'deptName'
        },
        reportDataqd:[],
        //当页总金额
        curPageAmount:'',
        //当月总金额
        curMonthAmount:'',
      };

    },
    created() {
      var myDate = new Date();
      var pp =myDate.getMonth()+1;       //获取当前月份(0-11,0代表1月)
      if(pp<9){
        pp = "0"+pp
      }
      this.queryParams.planMonth = myDate.getFullYear()+'-'+pp;
      this.getZhanxin()
      this.getTreeselect()
      this.getFeiyong()
      this.search()

    },
    methods: {
      getbanzhuData:function(id){
        debugger
        request({
          url: '/system/dept/listFrontTeam/'+id,
          method: 'get',
        }).then(response => {
          this.banzhuArr = response.data

        });
      },
      getFeiyong:function(){
        request({
          url: '/method/costproject/listCpName',
          method: 'get',
        }).then(response => {
          console.log(response.data)
          this.cpNameArr = response.data
          this.cpNameArr.unshift({
            cpName:'全部'
          })
        });
      },
      setValueNull(){
        this.queryParams.waId = null;
      },
      setValueNullqd(){
        this.queryParams.depId = null;
      },
      getTreeselect() {
        request({
          url: '/system/warehouse/listTree',
          method: 'get',
        }).then(response => {
          this.reportData =  response.data;
        });
      },
       //获取站线数据
      getZhanxin:function(){
        request({
          url: 'system/dept/treeselectNoTeam',
          method: 'get',
        }).then(response => {
          this.reportDataqd = response.data
          console.log('111',this.reportDataqd)
          this.reportDataqd.unshift(
            {depId:0,deptName:'全部'}
          )
        });
      },
      handleNodeClickSJ:function(node){
        this.queryParams.waId = node.id
        this.queryParams.wnameSJ = node.wname
        this.$refs.selectReport.blur()
      },
      //战线区队
       handleNodeClickSJqd:function(node){
        console.log('jiantin',node)
        this.queryParams.depId = node.deptId
        this.queryParams.deptName = node.deptName
         debugger
         if(node.deptId){
           this.getbanzhuData(node.deptId)
         }else {

         }

        this.$refs.selectReportqd.blur()
      },
      dateSelect() {
        if(this.date) {
            this.queryParams.startDate = this.date[0],
            this.queryParams.endDate = this.date[1]
        }else if(this.date==null) {
            this.queryParams.startDate='',
            this.queryParams.endDate =''
        }
      },
      //查询
      search:function(){

        if(this.queryParams.cpName=='全部'){
          this.queryParams.cpName=''
        }
        this.loading = true
        var queryParams = new Object();
        Object.keys(this.queryParams)
          .forEach(k=> queryParams[k] = this.queryParams[k]);
        if(queryParams.endDate){
          queryParams.endDate = queryParams.endDate + " 23:59:59"
        }
        request({
          url: '/material/apply/statistics/listInfoWithAmount',
          method: 'get',
          params:queryParams
        }).then(response => {
          this.loading = false
          this.roleList = response.rows
          console.log(this.roleList)
          this.total = response.total
          this.curPageAmount = response.additionalData.curPageAmount
          this.curMonthAmount = response.additionalData.curMonthAmount
        });
      },
      /** 导出按钮操作 */
      exportList() {
        this.$confirm('是否确认导出?', '警告', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(()=>{
          this.derive()
        }).catch((e)=> {
        })
      },
      //导出
      derive() {
        this.loading = true;
        var queryParams = new Object();
        Object.keys(this.queryParams)
          .forEach(k=> queryParams[k] = this.queryParams[k]);
        if(queryParams.endDate){
          queryParams.endDate = queryParams.endDate + " 23:59:59"
        }
        request({
          url: '/material/apply/statistics/exportInfoWithAmount',
          method: 'get',
          params:queryParams
        }).then(response => {
          this.loading = false
          return this.download(response.data)

        });
      },

    }
  };
</script>

<style lang="scss">
  .llmxcx{
    .bottomflot {
      height: 80px;
    }
    .pagination-container {
      display: inline-block;
      position: relative;
      height: 25px;
      margin-bottom: 10px;
      margin-top: 15px;
      padding: 10px 20px !important;
      float: right;
    }
    .box{
      float: left;
      font-size: 13px;
      color: #606266;
      line-height: 80px;
      margin-left: 15px;
    }
  }

 .datawidth {
    width: 250px;
  }
.el-input--small .el-input__inner {
  width: 250px;
}
.el-date-editor.el-input, .el-date-editor.el-input__inner{
   width: 250px;
}

</style>

